﻿Imports BUS
Imports DTO
Public Class MH_CapNhatDiemCaNhan
    Public MaLop As Integer
    Public MaHocSinh As Integer
    Public dataHocSinh As DataTable
    Dim old As Double
    Private Sub btnTim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTim.Click
        Dim frmTimKiem As New MH_TimKiemHocSinhNangCao()
        frmTimKiem.ShowDialog()
        Try
            dataHocSinh = frmTimKiem.dataTimKiem
            dgvDanhSachHocSinh.DataSource = dataHocSinh
        Catch ex As Exception

        End Try
    End Sub
    Private Sub btnXemDiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemDiem.Click
        Try
            Dim row As DataGridViewRow = dgvDanhSachHocSinh.CurrentRow
            Dim MaHocSinh As Integer = row.Cells("MAHOCSINH").Value
            Dim tempBUS As New BangDiemBUS
            Dim dataBangDiem As DataTable = tempBUS.LayBangDiem(MaHocSinh)
            dgvBangDiem.DataSource = dataBangDiem
            dgvBangDiem.Columns("MACHITIETDIEM").Visible = False
            dgvBangDiem.Columns("MAHOCSINH").Visible = False
            dgvBangDiem.Columns("MAMON").Visible = False
            dgvBangDiem.Columns("MACHITIETDIEM").Visible = False
            dgvBangDiem.Columns("MAHOCKY").Visible = False
            dgvBangDiem.Columns("MADIEMMONHOC").Visible = False
            dgvBangDiem.Columns("MALOP").Visible = False
            dgvBangDiem.Columns("TENMON").ReadOnly = True
            dgvBangDiem.Columns("HOCKY").ReadOnly = 1
        Catch ex As Exception
            MessageBox.Show("Hãy chọn 1 học sinh")
        End Try


    End Sub

    Private Sub btnCapNhatDiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatDiem.Click
        Dim BangDiem As New BangDiemDTO
        Try
            Dim row As DataGridViewRow = dgvBangDiem.CurrentRow
            BangDiem.MaChiTietDiem = row.Cells("MaChiTietDiem").Value
            BangDiem.Diem15P = row.Cells("DIEM15P").Value
            BangDiem.Diem1T = row.Cells("DIEM1T").Value
            BangDiem.DiemHK = row.Cells("DIEMHK").Value
            BangDiem.MaDiemMonHoc = row.Cells("MADIEMMONHOC").Value
            Dim tempBUS As New BangDiemBUS
            tempBUS.CapNhatBangDiem(BangDiem)
        Catch ex As Exception
            MessageBox.Show("Vui lòng chọn điểm bạn muốn cập nhật")
        End Try

    End Sub

    Private Sub btnXoaDiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaDiem.Click
        Dim BangDiem As New BangDiemDTO
        Try
            Dim row As DataGridViewRow = dgvBangDiem.CurrentRow
            BangDiem.MaChiTietDiem = row.Cells("MaChiTietDiem").Value
            BangDiem.Diem15P = row.Cells("DIEM15P").Value
            BangDiem.Diem1T = row.Cells("DIEM1T").Value
            BangDiem.DiemHK = row.Cells("DIEMHK").Value
            BangDiem.MaDiemMonHoc = row.Cells("MADIEMMONHOC").Value

            'goi bang kiem tra de xoa
            Dim frmYesNo As New MH_YesNo
            frmYesNo.ShowDialog()
            If (frmYesNo.flag) Then
                Dim tempBUS As New BangDiemBUS
                tempBUS.XoaBangDiemCuaMon(BangDiem)
                'btnXemDiem_Click(sender, e)
                Dim rowView As DataGridViewRow = dgvBangDiem.CurrentRow
                dgvBangDiem.Rows.Remove(rowView)
            End If
        Catch ex As Exception
            MessageBox.Show("Hãy chọn dòng muốn xóa")
        End Try


    End Sub

    Private Sub btnThemDiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemDiem.Click
        Try
            Dim row As DataGridViewRow = dgvBangDiem.CurrentRow
            MaLop = row.Cells("MaLop").Value
            MaHocSinh = row.Cells("MaHocSinh").Value
            Dim frmThemDiem As New MH_ThemDiem
            frmThemDiem.MaLop = MaLop
            frmThemDiem.MaHocSinh = MaHocSinh
            frmThemDiem.ShowDialog()
        Catch ex As Exception
            MessageBox.Show("Bạn chưa chọn 1 học sinh")
        End Try

    End Sub

    Private Sub dgvBangDiem_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvBangDiem.CellValueChanged
        Try
            Dim cell As DataGridViewCell = dgvBangDiem.CurrentCell
            If (cell.Value < 0 Or cell.Value > 10) Then
                MessageBox.Show("Điểm chỉ dc từ 0 đến 10")
                cell.Value = old
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub dgvBangDiem_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvBangDiem.CellMouseClick
        Try
            old = dgvBangDiem.CurrentCell.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub dgvBangDiem_CellMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvBangDiem.CellMouseDoubleClick
        Try
            old = dgvBangDiem.CurrentCell.Value
        Catch ex As Exception

        End Try
    End Sub
End Class